package com.itheima.health.controller;

import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Role;
import com.itheima.health.service.RoleService;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.SetmealVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Reference
    private UserService userService;

    @Reference
    private RoleService roleService;

    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult UserPageresult= userService.findPage(queryPageBean);
        return new Result(UserPageresult);
    }

    @GetMapping("/findAllRole")
    public Result findAllRole(){
        List<Role> roleList=roleService.list();
        return new Result(roleList);
    }

    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody UserVO userVO){
        Boolean add = userService.addAndUpdate(userVO);
        return new Result(add);
    }

    @GetMapping("findAllRoles/{id}")
    public Result findall(@PathVariable("id") Integer id){
        UserVO userVO  = userService.findroleandgroleids(id);
        return new Result(userVO);
    }

    //通过用户名查询菜单信息
    @GetMapping("findMenuInfoByUsername/{username}")
    public Result findMenuInfoByUsername(@PathVariable("username") String username){
        return new Result(userService.findMenuInfoByUsername(username));
    }
}
